/**
 * Copyright (C) 2009 Ignasi Fosch Alonso
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 
 * details.
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * You can reach me by mail at natx@y10k.ws
 * You can reach him by paper mail at:
 * C. LLEIDA, 41-43, 3r 1a
 * El Prat de Llobregat 08820
 * Barcelona, SPAIN
 */
package ws.y10k.vsmanager;

import java.rmi.RemoteException;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

import com.vmware.vim25.InvalidProperty;
import com.vmware.vim25.RuntimeFault;

import ws.y10k.vi.TreeLeaf;

/**
 * @author natx
 *
 */
public class HostListContentProvider implements ITreeContentProvider {
	
	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object)
	 */
	@Override
	public Object[] getElements(Object arg0) {
		return getChildren(arg0);
	}

	@Override
	public Object[] getChildren(Object arg0) {
		if ( arg0 instanceof TreeLeaf)
			try {
				return ((TreeLeaf)arg0).getChildren();
			} catch (InvalidProperty e) {
				// TODO Z: Check why this should happen
				e.printStackTrace();
			} catch (RuntimeFault e) {
				// TODO Z: Check why this should happen
				e.printStackTrace();
			} catch (RemoteException e) {
				// TODO Z: Check why this should happen
				e.printStackTrace();
			}
		return null;
	}

	@Override
	public Object getParent(Object arg0) {
		if ( arg0 instanceof TreeLeaf ) {
			return ((TreeLeaf) arg0).getParent();
		} else return null;
	}

	@Override
	public boolean hasChildren(Object arg0) {
		if ( arg0 instanceof TreeLeaf ) {
			return ((TreeLeaf) arg0).hasChildren();
		} else return false;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
	 */
	@Override
	public void dispose() { }

	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
	 */
	@Override
	public void inputChanged(Viewer arg0, Object arg1, Object arg2) { }

}
